package com.unionpay.mpds.web.action.factory;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.unionpay.mpds.model.Factory;
import com.unionpay.mpds.service.FactoryService;
import com.unionpay.mpds.util.Pager;
import com.unionpay.mpds.web.action.BaseAction;

@ParentPackage("json-center")
public class FactoryAction extends BaseAction {

	@Autowired
	private FactoryService factoryService;
	
	private List<Factory> factories;
	
	/**
	 * 获取所有设备厂商数据
	 * @return
	 * @throws Exception
	 */
	@Action(value="index", results={@Result(name="success", type="json", params={"root", "returnParams"})})
	public String index() throws Exception {
		factories = factoryService.getAll();
		returnParams.setDatas(factories);
		return SUCCESS;
	}
	
	/**
	 * 获取所有设备厂商数据（分页）
	 * @return
	 * @throws Exception
	 */
	@Action(value="indexpage", results={@Result(name="success", type="json", params={"root", "returnParams", "contentType", "application/x-www-form-urlencoded"})})
	public String indexpage() throws Exception {
		Pager<Factory> factories = factoryService.findPager(this.getPageNum(), this.getPageSize(), null);
		returnParams.setDatas(factories.getList());
		returnParams.setPageNum(factories.getPageNo());
		returnParams.setPageSize(factories.getPageSize());
		returnParams.setTotal(factories.getTotalCount());
		return SUCCESS;
	}

	public List<Factory> getFactories() {
		return factories;
	}

	public void setFactories(List<Factory> factories) {
		this.factories = factories;
	}

	public FactoryService getFactoryService() {
		return factoryService;
	}

	public void setFactoryService(FactoryService factoryService) {
		this.factoryService = factoryService;
	}

}
